package com.jimet.utils.mail;

import java.util.Vector;

import com.jimet.server.JimetConfiguration;

public class MutipleMailerThread extends Thread{

	private Mailer mail;
	private Vector<String> receivers;
	
	public MutipleMailerThread(Mailer pMail, Vector<String> pReceivers) {
		this.mail = pMail;
		this.receivers = pReceivers;
	}
	
	public MutipleMailerThread(Mailer pMail, String pReceiver) {
		this.mail = pMail;
		this.receivers = new Vector<String>();
		this.receivers.add(pReceiver);
	}
	public MutipleMailerThread( Mailer pMail ) {
		this.mail = pMail;
	}
	
	public void run() {
		Thread.yield();
		for ( int i = 0 ; i < this.receivers.size() ; i++ )
		{
			String strTo	= this.receivers.get(i);
			
			Mailer tmpMail	= new Mailer();
			tmpMail.setFROM(this.mail.getFROM());
			tmpMail.setFromName(this.mail.getFromName());
			tmpMail.setReceiverName("");
			tmpMail.setRecipientsBCC("");
			tmpMail.setSubject(this.mail.getSubject());
			tmpMail.setBody(this.mail.getBody());			
			tmpMail.setTO(strTo);
			//System.out.println("MutipleMailerThread : " + strTo );
			tmpMail.sendMail(JimetConfiguration.getString("SMTP.HOSTNAME"), JimetConfiguration.getString("SMTP.PORT") , JimetConfiguration.getString("SMTP.USERNAME") ,  JimetConfiguration.getString("SMTP.PASSWORD"));
		}
	}
}
